package cn.signalpha.modules.shop.wrapper;

import cn.signalpha.common.constant.MsgConstant;
import cn.signalpha.core.mp.support.BaseEntityWrapper;
import cn.signalpha.core.tool.utils.BeanUtil;
import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.core.tool.utils.SpringUtil;
import cn.signalpha.modules.shop.entity.OrderSettle;
import cn.signalpha.modules.shop.entity.Seller;
import cn.signalpha.modules.shop.service.OrderService;
import cn.signalpha.modules.shop.service.SellerService;
import cn.signalpha.modules.shop.vo.OrderSettleVO;

import java.util.Objects;

/**
 * 包装类,返回视图层所需的字段
 */
public class OrderSettleWrapper extends BaseEntityWrapper<OrderSettle, OrderSettleVO> {

    private static final OrderService orderService;
	private static final SellerService sellerService;

	static {
        orderService = SpringUtil.getBean(OrderService.class);
		sellerService = SpringUtil.getBean(SellerService.class);
	}

	public static OrderSettleWrapper build() {
		return new OrderSettleWrapper();
	}

	@Override
	public OrderSettleVO entityVO(OrderSettle orderSettle) {
        OrderSettleVO orderSettlementVO = Objects.requireNonNull(BeanUtil.copy(orderSettle, OrderSettleVO.class), MsgConstant.OBJECT_NULL);
		Seller seller = sellerService.getBaseById(orderSettlementVO.getSellerId());
		if(ObjectUtil.isNotEmpty(seller)){
			orderSettlementVO.setSellerName(seller.getName());
			orderSettlementVO.setSellerLogo(seller.getLogo());
			orderSettlementVO.setSellerMobile(seller.getMobile());
		}
		return orderSettlementVO;
	}

}
